package com.wenlin.myproduction.binder;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wenlin.myproduction.R;
import com.wenlin.myproduction.bean.RosterSelectBean;
import com.wenlin.myproduction.util.RosterUtil;
import com.wenlin.myproduction.util.TypeData;
import com.wenlin.myproduction.util.TypeDataNames;
import com.wenlin.myproduction.util.UI;

import org.greenrobot.eventbus.EventBus;

import me.drakeet.multitype.ItemViewBinder;

/**
 * @author 文琳_377979485@qq.com
 * @time 2021/10/18 0018 上午 8:29
 * @desc 选择班次弹窗的列表条目
 */
public class RosterSelectBinder extends ItemViewBinder<RosterSelectBean, RosterSelectBinder.RosterSelectHolder> {

    @NonNull
    @Override
    protected RosterSelectHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        return new RosterSelectHolder(inflater.inflate(R.layout.item_roster_select, parent, false));
    }

    @Override
    protected void onBindViewHolder(@NonNull RosterSelectHolder holder, @NonNull RosterSelectBean item) {
        UI.setText(holder.tvName, item.getName());
        UI.setText(holder.tvDuration, item.getDuration());
        UI.setText(holder.tvStartAndEndTime, RosterUtil.getFormatStartAndEndTime(item));
        UI.setVisibleInvisible(holder.vBg, item.isSelected());
        UI.setOnClickListener(holder.itemView, v -> EventBus.getDefault().post(new TypeData<>(TypeDataNames.clickItemRosterSelect, item)));
    }

    static class RosterSelectHolder extends RecyclerView.ViewHolder {
        TextView tvName, tvDuration, tvStartAndEndTime;
        View vBg;

        public RosterSelectHolder(@NonNull View itemView) {
            super(itemView);
            tvName = itemView.findViewById(R.id.tv_title1);
            tvDuration = itemView.findViewById(R.id.tv_title2);
            tvStartAndEndTime = itemView.findViewById(R.id.tv_title3);
            vBg = itemView.findViewById(R.id.v_bg);
        }
    }
}
